package com.kjlink.widget.monitoring.enums;

import com.kjlink.widget.monitoring.model.BaseMonitorDataExtraModel;
import com.kjlink.widget.monitoring.model.extra.CloudFinanceConnFailExtraModel;
import com.kjlink.widget.monitoring.model.extra.CredentialTransferExtraModel;
import com.kjlink.widget.monitoring.model.extra.ProcessEngineErrorExtraModel;
import com.kjlink.widget.monitoring.model.extra.YonyouConnFailExtraModel;

/**
 * 描述:
 * 事件源枚举
 *
 * @author Vic.xu
 * @since 2025-08-01 15:29
 */
public enum EventTypeEnum {


    CREDENTIAL_TRANSFER_FAIL("凭证传输失败", "CREDENTIAL_TRANSFER_FAIL",
            EventTypeApplicationEnum.CPLEASE, EventTypeApplicationEnum.YONYOU,
            CredentialTransferExtraModel.class),
    PROCESS_ENGINE_ERROR("流程引擎报错", "PROCESS_ENGINE_ERROR",
            EventTypeApplicationEnum.CPLEASE, EventTypeApplicationEnum.CPLEASE,
            ProcessEngineErrorExtraModel.class),
    YONYOU_CONN_FAIL("用友系统连通性中断", "YONYOU_CONN_FAIL",
            EventTypeApplicationEnum.CPLEASE, EventTypeApplicationEnum.YONYOU,
            YonyouConnFailExtraModel.class),
    CLOUD_FINANCE_CONN_FAIL("财资云系统连通性中断", "CLOUD_FINANCE_CONN_FAIL",
            EventTypeApplicationEnum.CPLEASE, EventTypeApplicationEnum.CLOUD_FINANCE,
            CloudFinanceConnFailExtraModel.class),
    ;
    /**
     * 事件名称
     */
    private String name;
    /**
     * 事件code
     */
    private String code;
    /**
     * 业务源应用
     */
    private EventTypeApplicationEnum source;

    /**
     * 业务目标应用
     */
    private  EventTypeApplicationEnum target;

    private Class<? extends BaseMonitorDataExtraModel> extraClass;


    EventTypeEnum(String name, String code, EventTypeApplicationEnum source, EventTypeApplicationEnum target,
            Class<? extends BaseMonitorDataExtraModel> extraClass) {
        this.name = name;
        this.code = code;
        this.source = source;
        this.target = target;
        this.extraClass = extraClass;
    }

    /**
     * 根据枚举 字面量获取 枚举
     */
    public static EventTypeEnum getType(String typeStr) {
        for (EventTypeEnum value : values()) {
            if (value.name().equalsIgnoreCase(typeStr)) {
                return value;
            }
        }
        return null;
    }

    public String getName() {
        return name;
    }

    public String getCode() {
        return code;
    }

    public Class<? extends BaseMonitorDataExtraModel> getExtraClass() {
        return extraClass;
    }

    public EventTypeApplicationEnum getSource() {
        return source;
    }

    public EventTypeApplicationEnum getTarget() {
        return target;
    }
}
